<?php
$userid = $_SESSION['user_id'];




    $userinfo   = $user_controller->ShowUserInfo($userid);
    $firstname  = $userinfo[0]->firstname; 
    $lastname   = $userinfo[0]->lastname;
    $username   = $userinfo[0]->username;
    $year       = $userinfo[0]->yearborn;
    $sex        = $userinfo[0]->sex;
    $zipcode    = $userinfo[0]->zipcode;
    $user2      = $userinfo[2];
    $password   = "";
    $email      = $user2[0]->email;
    
    if(isset($_POST['showuser'])){
        
        $firstname  = $_POST['firstname'];
        $lastname   = $_POST['lastname'];
        $username   = $_POST['username'];
        $year       = $_POST['yearborn'];
        $sex        = $_POST['sex'];
        $zipcode    = $_POST['zipcode'];
        
        $message1    = $user_controller->changeUserInfo($firstname, $lastname, $username, $year, $sex, $zipcode, $userid);
    }
    if(isset($_POST['showemail'])){
        
        $email          = $_POST['email'];
        $oldpassword    = $_POST['oldpassword'];
        
        $message2        = $user_controller->changeLoginInfo($userid,$email,$oldpassword);
    }
    if(isset($_POST['showpassword'])){
    
        $oldpassword    = $_POST['oldpassword'];
        $newpassword    = $_POST['newpassword'];
        $newpassword1   = $_POST['newpassword1'];
        
        $message3        = $user_controller->changeLoginPass($userid,$oldpassword,$newpassword,$newpassword1);
    
}



?>
<fieldset id="uform">
    
    
    
    <legend>Personalia</legend>
    
   <?php
    if(isset($message1)){
        echo "<div id='error'>".$message1. "</div>";
    }
    ?>
   
    
    
    <form id="showuser" method="post" action="#"  >
            <p>
            <label > Fornavn</label> <em></em><input type="text" name="firstname" size="25" required="required" value="<?php echo htmlentities($firstname);?>"/><br />
           </p> <p>
            <label> Etternavn </label> <em></em><input type="text" name="lastname" size="25" required="required"    value="<?php echo htmlentities($lastname);?>"/><br />
            </p><p>
            <label> Fødselsår </label> <em></em>
            <select name="yearborn">
            <option ><?php echo htmlentities($year);?></option>

                <?php 
                    $cur = date("Y", time());
                    $cur1 = $cur -10;
                for($i=$cur1;$i>1920;$i--){
                    echo ('<option value="'.$i.'" >'.$i.'</option>');
                }            ?>

            </select></p>
                <p>
            <label > Visningsnavn</label> <em></em><input type="text" name="username" size="25" required="required"  value="<?php echo htmlentities($username);?>"/><br />
</p><p>
            <label>Kjønn:</label> <em></em>
                            <input type="radio" required x-moz-errormessage="Velg kjønn" name="sex" id="sex" value="male" <?php if($sex == "male"){echo "checked";} ?> /> Mann
                            <input type="radio" required x-moz-errormessage="Velg kjønn" name="sex" id="sex" value="female" <?php if($sex == "female"){echo "checked";} ?> /> Kvinne <br />	        
            </p>
            <p>
            <label> Postnummer </label> <em></em><input type="number" name="zipcode" size="25" required="required" max="4" value="<?php echo htmlentities($zipcode);?>" /><br />
</p>
            <label></label><input id="btn" type="submit" name="showuser" value="Endre Brukerinformasjon" /> <br />
    </form>
</fieldset>

<fieldset id="uform">
    
    
    
    <legend>Brukerinfo</legend>
    
    <?php
    if(isset($message2)){
        echo "<div id='error'>".$message2. "</div>";
    }
    ?>
      
    <form id="showlogin" method="post" action="#" >
            <p>
            <label > Email</label> <em></em><input type="text" name="email" size="25" required="required" minlength="2" value="<?php echo htmlentities($email);?>"/><br />
            </p><p>
            <label >  Passord</label> <em></em><input type="password" name="oldpassword" size="25" required="required" minlength="2" value="<?php echo htmlentities($password);?>"/><br />
            </p><p>
            <label ></label><input id="btn" type="submit" name="showemail" value="Endre Epost">
            </p>
    </form>
    
</fieldset>
    
<fieldset id="uform">
    
    
    <legend>Nytt passord</legend>
    
    <?php
    if(isset($message3)){
    echo "<div id='error'>".$message3. "</div>";
    }
    ?>
    <form id="showlogin" method="post" action="#" >
        </br>

<p>
        <label > Gammelt Passord</label> <em></em><input type="password" name="oldpassword" size="25" required="required" minlength="2" value="<?php echo htmlentities($password);?>"/><br />

        </p><p>

        <label > Nytt Passord</label> <em></em><input type="password" name="newpassword" size="25" required="required" minlength="2" value="<?php echo htmlentities($password);?>"/><br />

        </p><p>

        <label > Gjenta Nytt Passord</label> <em></em><input type="password" name="newpassword1" size="25" required="required" minlength="2" value="<?php echo htmlentities($password);?>"/><br />
        </p>
        <label ></label><input id="btn" type="submit" name="showpassword" value="Endre Passord">

    </form>
</fieldset>